﻿/*=========================================================================================
	TASK 8:                                                                        {Loop's}
	Write a program that calculates the greatest common divisor (GCD) of given two numbers.
    Use the Euclidean algorithm (find it in Internet). 
=========================================================================================*/

using System;

class GreatestCommonDivisorGCD
{
    static void Main()
    {
        Console.Write("Enter a=");
        double a = double.Parse(Console.ReadLine());

        Console.Write("Enter b=");
        double b = double.Parse(Console.ReadLine());

        bool defferentThanZero = (a != 0) || (b != 0);
        bool notEquals = a != b;

        double c;
        double reminder;
        double newB=0;
        double newA;

        if (defferentThanZero && notEquals)
        {
            if (a < b)
            {
                c = b;
                b = a;
                a = c;
            }

            reminder = a % b;

            if (reminder != 0)
            {
                do
                {
                    newB = reminder;
                    newA = b;
                    reminder = b % newB;
                    newA = newB;
                } while (reminder != 0);
            }

            Console.WriteLine("GCD={0}", newB);

        }
        else
        {
            if (a == 0 && b == 0)
            {
                Console.WriteLine("a or b must be a different that zero");
            }
            else
            {
                Console.WriteLine("a and b must not be equals");
            }
        }
    }
}

